#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h> 

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};

struct TreeNode* invertTree(struct TreeNode* root) {
    if (!root || (!root->left) && (!root->right))
        return root;
    struct TreeNode* left = root->left;
    struct TreeNode* right = root->right;
    root->left = right;
    root->right = left;

    invertTree(root->left);
    invertTree(root->right);
    return root;
}